package com.wenhao.bluelake;

import java.util.*;

/**
 * @author Wenhao Tong
 * @create 2021-09-04 9:21
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            String[] proxy = new String[n];
            for (int i = 0;i < n;i++) {
                proxy[i] = scanner.next();
            }
            int m = scanner.nextInt();
            String[] server = new String[m];
            for (int i = 0;i < m;i++) {
                server[i] = scanner.next();
            }

            int serverIndex = 0;
            int max;
            int result = -1;
            while (serverIndex < m) {
                max = 0;
                for (int i = 0;i < n;i++) {
                    int t = 0;
                    int count = 0;
                    while (serverIndex + t < m && proxy[i].equals(server[serverIndex + t])) {
                        t++;
                        count++;
                    }
                    max = Math.max(count,max);
                }
                if (max == 0) {
                    break;
                }
                serverIndex += max;
                result++;
            }
            System.out.println(result);
        }
    }
}
